﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;

namespace Wintellect.Touch.Views
{
    public partial class ElementResizingPage : Page
    {
        public ElementResizingPage()
        {
            InitializeComponent();
            LoadNextImage();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void HandleClipToParentCheckChanged(Object sender, RoutedEventArgs e)
        {
            if (ResizeImageBehavior == null || ResizeShapeBehavior == null) return;
            ResizeImageBehavior.ClipToParent = ClipToParentCheckBox.IsChecked == true;
            ResizeShapeBehavior.ClipToParent = ClipToParentCheckBox.IsChecked == true;
        }

        private void HandleLimitMinimumScaleCheckChanged(Object sender, RoutedEventArgs e)
        {
            if (ResizeImageBehavior == null || ResizeShapeBehavior == null) return;
            ResizeImageBehavior.LimitMinimumScaleToOriginalSize = LimitMinimumScaleCheckBox.IsChecked == true;
            ResizeShapeBehavior.LimitMinimumScaleToOriginalSize = LimitMinimumScaleCheckBox.IsChecked == true;
        }

        private void HandleLimitTranslationCheckChanged(Object sender, RoutedEventArgs e)
        {
            if (ResizeImageBehavior == null || ResizeShapeBehavior == null) return;
            ResizeImageBehavior.LimitTranslationToParentBounds = LimitTranslationCheckBox.IsChecked == true;
            ResizeShapeBehavior.LimitTranslationToParentBounds = LimitTranslationCheckBox.IsChecked == true;
        }

        private void HandleResetOnImageChangeCheckChanged(Object sender, RoutedEventArgs e)
        {
            if (ResizeImageBehavior == null) return;
            ResizeImageBehavior.ResetScaleAndTranslationOnImageOpened = ResetOnImageChange.IsChecked == true;
        }

        private void HandleNextImageButtonClick(Object sender, RoutedEventArgs e)
        {
            LoadNextImage();
        }

        private Int32 _currentImageIndex = -1;

        private void LoadNextImage()
        {
            _currentImageIndex = (_currentImageIndex + 1) % 5;
            switch(_currentImageIndex)
            {
                case 0:
                    ResizeImage.Source = new BitmapImage(new Uri("/Wintellect.Touch.Sample;component/SampleData/SampleDataSource/SampleDataSource_Files/image01.png", UriKind.Relative));
                    break;
                case 1:
                    ResizeImage.Source = new BitmapImage(new Uri("/Wintellect.Touch.Sample;component/SampleData/SampleDataSource/SampleDataSource_Files/image02.png", UriKind.Relative));
                    break;
                case 2:
                    ResizeImage.Source = new BitmapImage(new Uri("/Wintellect.Touch.Sample;component/SampleData/SampleDataSource/SampleDataSource_Files/image03.png", UriKind.Relative));
                    break;
                case 3:
                    ResizeImage.Source = new BitmapImage(new Uri("/Wintellect.Touch.Sample;component/SampleData/SampleDataSource/SampleDataSource_Files/image04.png", UriKind.Relative));
                    break;               
                case 4:
                    ResizeImage.Source = new BitmapImage(new Uri("/Wintellect.Touch.Sample;component/SampleData/SampleDataSource/SampleDataSource_Files/image05.png", UriKind.Relative));
                    break;
            }
        }

        private void HandleResetElementClick(Object sender, RoutedEventArgs e)
        {
            if (ResizeImageBehavior == null || ResizeShapeBehavior == null) return;
            ResizeImageBehavior.ResetElement();
            ResizeShapeBehavior.ResetElement();
        }
    }
}
